<template>
  <div class="app-container">
    
      <!--院系汇总-->

        <searchForm
          :formOptions="formOptions"
          @onSearch="onSearch"
          @onReset="onReset"
          :formLabelWidth="formLabelWidth"
          v-show="showSearch"
        />

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['clr:examinescoring:summary:deptexport']"
        >导出</el-button>
      </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <el-table 
        :data="list.slice((queryParams.pageNum-1)*queryParams.pageSize,queryParams.pageNum*queryParams.pageSize)">
          <el-table-column label="序号" align="center" type="index" />
          <el-table-column label="批次名称" align="center" prop="batchName" />
          <el-table-column label="学年" align="center" prop="amcYear" />
          <el-table-column label="辅导员工号" align="center" prop="clrTno" />
          <el-table-column label="辅导员名称" align="center" prop="clrName" />
          
          <el-table-column label="等级" align="center" prop="rank">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.clr_sum_rank" :value="scope.row.rank" />
            </template>
          </el-table-column>
          
          <el-table-column label="指标分类" align="center" prop="classifyName" :show-overflow-tooltip="true"/>
          <el-table-column label="总分数" sortable align="center" prop="sumscore"/>
          <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="details(scope.row)"
                v-hasPermi="['clr:examineStatistics:details']"
              >查看详情</el-button>
            </template>
          </el-table-column> -->
        </el-table>
        <el-pagination
        style="text-align: right;"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryParams.pageNum"
        :page-sizes="[10,20,30,50]"
        :page-size="10"
        background
        layout="total, sizes, prev, pager, next, jumper"
        :total="list.length"
      ></el-pagination>
    <!-- 添加或修改辅导员考核指标对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <!-- <el-table
      :data="scoreList"
      style="width: 100%">
      <el-table-column
      v-for="item in scoreList"
      :key="item.prop"
        :label="item.classifyName"
        :prop="item.classifyTotalScore +''"
       >
      </el-table-column>
    </el-table> -->
      <table border="1" align="center" class="default-table" width="100%" height="100%" cellspacing="0">
        <tr align="center" height="50px" cellspacing="0">
          <th>姓名</th>
          <th  v-for="(v,i) in scoreData.classifySummaryList" :key="i">{{ v.classifyName }}</th>
        </tr>
        <tr  align="center" height="50px" cellspacing="0">
          <th>{{ scoreData.clrName }}</th>
          <th  v-for="(v,i) in  scoreData.classifySummaryList" :key="i">{{ v.classifyTotalScore }}</th>
        </tr>
      </table>
    </el-dialog>
  </div>
</template>

<script>
import { deptlist, summary,summaryExport } from "@/api/clr/statistics";
import searchForm from "@/components/Search/searchForm.vue";
import { getDicts } from "@/api/system/dict/type";
import { getSelector} from "@/api/clr/batch";
export default {
  dicts: [
    "clr_grade_type", // 年级批次
    "clr_sum_rank", // 等级
  ],
  components: {
    searchForm
  },
  data() {
    return {
      formLabelWidth: "85px",
      formOptions: [
        {
          label: "辅导员工号",
          prop: "clrTno",
          element: "el-input",
          placeholder: "请输入辅导员工号"
        },
        {
          label: "辅导员姓名",
          prop: "clrName",
          element: "el-input",
          placeholder: "请输入辅导员姓名"
        },
        {
          label: "批次名称",
          prop: "cebId",
          element: "el-select",
          options: [],
          placeholder: "请输入批次名称"
        },
      
        {
          label: "等级",
          prop: "rank",
          element: "el-select",
          options: [],
          placeholder: "请选择等级"
        },
        {
          label: "学年",
          prop: "amcYears",
          type: "monthrange",
          initValue: null,
          element: "el-date-picker",
          placeholder: "请选择学年",
          valueFormat: "yyyy-MM"
        }
      ],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      list: [],
      scoreData: {
      },
      open: false,
      title: "",
      // 显示搜索条件
      showSearch: true,
      deptOptions: [],
    };
  },
  created() {
    this.getList();
    getDicts("clr_sum_rank").then(res => {
      this.formOptions[3].options = res.data.map(item => {
        return {
          value: item["dictValue"],
          label: item["dictLabel"]
        };
      });
    });
    getSelector({cebType:'A'}).then(res => {
      this.formOptions[2].options = res.data.map(item => {
        return {
          value: item["CEBID"],
          label: item["BATCHNAME"]
        };
      });
    })
  },
  methods: {
    // 获取搜索表单提交的数据
    onSearch(val) {
      // 查询条件和分页数据合并
      if(val.amcYears) {
        val.startAmcYear = val.amcYears[0];
        val.endAmcYear = val.amcYears[1];
      }
      this.queryParams = Object.assign(this.queryParams, val);
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置
    onReset(data) {
      data.startAmcYear = undefined
      data.endAmcYear = undefined
      this.queryParams.pageNum = 1;
      this.queryParams = Object.assign(this.queryParams, data);
      this.getList();
    },
    //pageSize改变时触发的事件
    handleSizeChange(val) {
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = val;
    },
    //当前页码发生改变时触发的事件
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
    },
  
    // 导出操作
    handleExport() {
      // summaryExport().then(res => {
      //   console.log(res,'export')
      // })
      this.download(
            "/clr/examinescoring/summary/deptexport",
            {
              ...this.queryParams,
            },
            `辅导员院系考核汇总表${new Date().getFullYear()}-${new Date().getMonth() +
              1}-${new Date().getDate()}.xlsx`
          );
    },
    // tree树形选中的值
    handleNodeClick(data) {

      console.log(data, "选中的值");
      this.queryParams.deptId = data.id;
      this.getList();
    },
    getList() {
      deptlist(this.queryParams).then(res => {
        this.list = res.data;
        console.log(res, "summary");
      });
    },
    details(row) {
      summary(row.cemId).then(res => {
        console.log(res, "123");
        if (res.code == 200) {
          this.scoreData = res.data
          // this.scoreData.scoreList = res.data.classifySummaryList;
          this.title = "辅导员工作考核得分表";
          this.open = true;
        }
      });
    }
  }
};
</script>

<style>
</style>